define([
  'jquery',
  'underscore',
  'backbone',
  'dateformatter',
  'models/admin/ApproveUsersModel',
  'collections/admin/ApproveUsersCollection',
  'views/admin/ApproveUsersListView',
  'text!templates/admin/approveUsersTemplate.html'
], function($, _, Backbone,Dateformatter, ApproveUsersModel, ApproveUsersCollection, ApproveUsersListView, approveUsersTemplate){

  var ApproveUsersView = Backbone.View.extend({
    el: $(".mainpanel"),
    events: {'click #saveUserStatus' : 'savePayments', 'change .approveuser':'addtomodel'} ,
    render: function(){
    	this.$el.html(approveUsersTemplate);
        var approveUsersCollection = new ApproveUsersCollection();
        var lOptions = {};
        var self=this;
        lOptions.success = function(){
        	var approveUsersListView = new ApproveUsersListView({ collection: approveUsersCollection});
        	approveUsersListView.render();
        	self.approveUsersListView =approveUsersListView; 
        };
        approveUsersCollection.fetch(lOptions);
    },
    savePayments: function(){
    	console.log(this.approveUsersListView.collection);
    	this.approveUsersListView.collection.save();
 		 $.msgBox({
			    title:"Appment",
			    content:"Successfully Saved!",
			    type:"info"
			});
    },
    addtomodel: function(evt){
    	var changed=evt.currentTarget;
    	var model = this.approveUsersListView.collection.get(changed.id);
    	console.log(changed);
    	model.get("doctor").approved == "Y"?model.get("doctor").approved="":model.get("doctor").approved="Y";
    	console.log(model);
    }
  });

  return ApproveUsersView;
});
